Skip to content

Comments

fix: types for query values#3985

Merged
wellwelwel merged 6 commits intosidorares:masterfrom
uPaymeiFixit:master
Feb 20, 2026
Merged

fix: types for query values#3985
wellwelwel merged 6 commits intosidorares:masterfrom
uPaymeiFixit:master

Conversation

@uPaymeiFixit
Copy link
Contributor

Fixes #3982

@codecov

This comment was marked as off-topic.

@uPaymeiFixit
Copy link
Contributor Author

@wellwelwel I see you added the needs documentation tag. Is this what you had in mind?
image

@wellwelwel
Copy link
Collaborator

I see you added the needs documentation tag. Is this what you had in mind?

Yes, thanks @uPaymeiFixit! I don't know how these types perform in general with variations such as placeholders, nested arrays, and complex parameter combinations, especially in the case of query, which allows for more flexible values. That's why I put the needs investigation label on it.

For TypeScript, there are compilation tests (which do not execute code, but only check types usage), for example:

conn.query<mysqlp.ProcedureCallPacket>(sql).then(([_r, _f]) => {
const result:
| [mysqlp.RowDataPacket[], mysqlp.ResultSetHeader]
| mysqlp.ResultSetHeader = _r;
const fields: mysqlp.FieldPacket[] = _f;
console.log(result, fields);
});

You can run them with test:tsc-build 🙋🏻‍♂️

@uPaymeiFixit
Copy link
Contributor Author

Awesome! I ran the test:tsc-build script and it looks like it succeeded (exited with 0).
As far as investigation goes, I initially did a lot of playing around with the type to make sure it was accurate. I think it should reflect what types are actually possible. Here's a tsplayground that shows what's possible and what's not.

@wellwelwel
Copy link
Collaborator

wellwelwel commented Feb 17, 2026

@uPaymeiFixit, my main concern was how these types would behave with named-placeholders. By migrating the entire ESM test suite to TypeScript in #4086, the types you created are now tested. You can check it with npm run typecheck 🙋🏻‍♂️

@uPaymeiFixit
Copy link
Contributor Author

Good catch, I completely forgot about named placeholders. In case it's helpful, I also updated my tsplayground test.

@wellwelwel
Copy link
Collaborator

wellwelwel commented Feb 20, 2026

Thanks again, @uPaymeiFixit!

Just to be sure, I tried a random case with nested arrays:

query('INSERT ...', ['john', 30, [[[{a: true}], 6]]]); // ✅

@wellwelwel wellwelwel merged commit a9c8d09 into sidorares:master Feb 20, 2026
101 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type of value is incorrect (Type is any, should be more specific)

2 participants